home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 60 / IOPROG_60.ISO / soft / c++ / gsl-1.1.1-setup.exe / {app} / src / ieee-utils / fp-aix.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-05-14  |  3.1 KB  |  115 lines

  1. /* ieee-utils/fp-aix.c
  2.  * 
  3.  * Copyright (C) 1996, 1997, 1998, 1999, 2000 Tim Mooney
  4.  * 
  5.  * This program is free software; you can redistribute it and/or modify
  6.  * it under the terms of the GNU General Public License as published by
  7.  * the Free Software Foundation; either version 2 of the License, or (at
  8.  * your option) any later version.
  9.  * 
  10.  * This program is distributed in the hope that it will be useful, but
  11.  * WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  * General Public License for more details.
  14.  * 
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program; if not, write to the Free Software
  17.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20. #include <math.h>
  21. #include <fptrap.h>
  22. #include <float.h>
  23. #include <gsl/gsl_ieee_utils.h>
  24. #include <gsl/gsl_errno.h>
  25.  
  26. int
  27. gsl_ieee_set_mode (int precision, int rounding, int exception_mask)
  28. {
  29.   fptrap_t   mode = 0 ;
  30.   fprnd_t    rnd  = 0 ;
  31.  
  32.   switch (precision)
  33.     {
  34.  
  35.     /* I'm not positive about AIX only supporting default precision rounding,
  36.      * but this is the best assumption until it's proven otherwise. */
  37.  
  38.     case GSL_IEEE_SINGLE_PRECISION:
  39.       GSL_ERROR ("AIX only supports default precision rounding",
  40.          GSL_EUNSUP) ;
  41.       break ;
  42.     case GSL_IEEE_DOUBLE_PRECISION:
  43.       GSL_ERROR ("AIX only supports default precision rounding",
  44.          GSL_EUNSUP) ;
  45.       break ;
  46.     case GSL_IEEE_EXTENDED_PRECISION:
  47.       GSL_ERROR ("AIX only supports default precision rounding",
  48.          GSL_EUNSUP) ;
  49.       break ;
  50.     }
  51.  
  52.   switch (rounding)
  53.     {
  54.     case GSL_IEEE_ROUND_TO_NEAREST:
  55.       rnd = FP_RND_RN ;
  56.       fp_swap_rnd (rnd) ;
  57.       break ;
  58.     case GSL_IEEE_ROUND_DOWN:
  59.       rnd = FP_RND_RM ;
  60.       fp_swap_rnd (rnd) ;
  61.       break ;
  62.     case GSL_IEEE_ROUND_UP:
  63.       rnd = FP_RND_RP ;
  64.       fp_swap_rnd (rnd) ;
  65.       break ;
  66.     case GSL_IEEE_ROUND_TO_ZERO:
  67.       rnd = FP_RND_RZ ;
  68.       fp_swap_rnd (rnd) ;
  69.       break ;
  70.     default:
  71.       rnd = FP_RND_RN ;
  72.       fp_swap_rnd (rnd) ;
  73.     }
  74.  
  75.   /* Turn on all the exceptions apart from 'inexact' */
  76.  
  77.   mode = TRP_INVALID | TRP_DIV_BY_ZERO | TRP_OVERFLOW | TRP_UNDERFLOW ;
  78.  
  79.   if (exception_mask & GSL_IEEE_MASK_INVALID)
  80.     mode &= ~ TRP_INVALID ;
  81.  
  82.   if (exception_mask & GSL_IEEE_MASK_DENORMALIZED)
  83.     GSL_ERROR ("AIX does not support the denormalized operand exception. "
  84.            "Use 'mask-denormalized' to work around this.",
  85.            GSL_EUNSUP) ;
  86.  
  87.   if (exception_mask & GSL_IEEE_MASK_DIVISION_BY_ZERO)
  88.     mode &= ~ TRP_DIV_BY_ZERO ;
  89.  
  90.   if (exception_mask & GSL_IEEE_MASK_OVERFLOW)
  91.     mode &= ~ TRP_OVERFLOW ;
  92.  
  93.   if (exception_mask & GSL_IEEE_MASK_UNDERFLOW)
  94.     mode &=  ~ TRP_UNDERFLOW ;
  95.  
  96.   if (exception_mask & GSL_IEEE_TRAP_INEXACT)
  97.     {
  98.       mode |= TRP_INEXACT ;
  99.     }
  100.   else
  101.     {
  102.       mode &= ~ TRP_INEXACT ;
  103.     }
  104.  
  105.   /* AIX appears to require two steps -- first enable floating point traps
  106.    * in general... */
  107.   fp_trap(FP_TRAP_SYNC);
  108.  
  109.   /* next, enable the traps we're interested in */
  110.   fp_enable(mode);
  111.  
  112.   return GSL_SUCCESS ;
  113.  
  114. }
  115.